package org.shijiagen.cart.listener;

import lombok.RequiredArgsConstructor;
import org.shijiagen.cart.service.CartService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class CartRabbitListener {

    private final CartService cartService;

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "clear.queue"),
                    exchange = @Exchange("topic.ex"),
                    key = "clear.cart"
            )
    )
    public void clearProduct(List<Integer> cartIds){
        cartService.clearIds(cartIds);
    }
}
